package com.example.springbootmybatisplus.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.springbootmybatisplus.entity.User;
import com.example.springbootmybatisplus.mapper.UserMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.List;

/**
 * @author liyang
 * @version 1.0
 * @Title: UserController
 * @description TODO
 * @date 2021/6/7 15:41
 */

@RestController
public class UserController {

    @Resource
    private UserMapper userMapper;

    @PostMapping("/user")
    public User saveUser(@RequestBody User user) {
        userMapper.insert(user);
        return user;
    }


    @GetMapping("/user/{id}")
    public User getUser(@PathVariable long id) {
        User user = userMapper.selectById(id);
        return user;
    }

    @GetMapping("/users")
    public List<User> getUsers() {
        return userMapper.selectList(Wrappers.lambdaQuery());
    }

    @DeleteMapping("/user/{id}")
    public int delUser(@PathVariable long id) {
        return userMapper.deleteById(id);
    }

    @PutMapping("/user")
    public int modifyUser(@RequestBody User user) {
        return userMapper.updateById(user);
    }


}